package juc.thread.secuity;
/*
* 活跃性-活锁
* 解决方案- 1.让睡眠时间为一个随机数 2.让两个反向操作指令交错执行
* */
public class Test15 {
    private static int num=10;
    public static void main(String[] args) throws InterruptedException {
           new Thread(()->{
               while (num>0){
                   try {
                       Thread.sleep(200);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   num--;
               }
           },"t1").start();
        new Thread(()->{
            while (num<20){
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                num++;
            }
        },"t2").start();
        while (num>0&&num<20){
            Thread.sleep(200);
            System.out.println(num);
        }
    }
}
